
tpl1="""
execute if score @s advm_battery_swapper_available matches {id} store result storage advm:temp swap_power int 1 run data get entity @s Inventory[{{Slot:{id}b}}].tag.power

"""
tpl2="""
execute as @s[nbt={{Inventory:[{{Slot:{id}b,tag:{{id:"advm:battery",chargeable:0b}}}}]}}] if score @s advm_battery_swapper_available matches {id} run loot replace entity @s container.{id} loot advm:battery_used_up
data modify storage advm:temp amount set value 0
execute as @s[nbt={{Inventory:[{{Slot:{id}b,tag:{{id:"advm:battery",chargeable:1b}}}}]}}] if score @s advm_battery_swapper_available matches {id} run item modify entity @s container.{id} advm:set_amount
"""
with open("gen.txt","w+") as f:
    f.write("function advm:skills/battery_swapper_detect\n")
    for i in range(0,36):
        f.write(tpl1.format(id=str(i)))
    f.write("execute if score @s advm_battery_swapper_available matches 0.. run item modify entity @s weapon.offhand advm:set_swapper_power\n")
    for i in range(0,36):
        f.write(tpl2.format(id=str(i)))
    f.write("scoreboard players set @s advm_battery_swapper_available -1")